import { ApiProperty } from '@nestjs/swagger';
import { IsOptional } from 'class-validator';
import { CreateLessonsSortDto } from './create-lessons-sort.dto';
import { Transform } from 'class-transformer';

// 用户模糊搜索
export class GetLessonsSortDto {
  @ApiProperty({ example: '1', description: '页码', required: true })
  @IsOptional()
  page: number;

  @ApiProperty({ example: '10', description: '页数', required: false })
  @IsOptional()
  limit?: number;

  @ApiProperty({ example: '', description: '教室id', required: false })
  @IsOptional()
  class_room_id?: number;

  @ApiProperty({ example: '', description: '课程id', required: false })
  @IsOptional()
  course_id?: number;

  @ApiProperty({ example: '', description: '老师id', required: false })
  @IsOptional()
  teacher_id?: number;

  @ApiProperty({ example: '', description: '综合搜索', required: false })
  @IsOptional()
  blur?: string;
}

// swagger 返回dto
export class ReturnLessonsSortDtoList {
  @ApiProperty({ type: [CreateLessonsSortDto], description: '列表内容' })
  @Transform(({ value }) => {
    console.log('Original Value:', value); // 检查原始值
    const transformedItems = value.map((item) => {
      console.log('Item:', item); // 输出每个item的值
      return item;
    });
    console.log('Transformed Items:', transformedItems); // 检查转换后的值
    return transformedItems;
  })
  content: CreateLessonsSortDto[];

  @ApiProperty({ description: '页码' })
  totalElements: number;

  @ApiProperty({ description: '页数' })
  totalPages?: number;
}
